//
//  UIImageView+Extension.swift
//  WeiBo2017
//
//  Created by 王璐 on 2017/4/19.
//  Copyright © 2017年 wl. All rights reserved.
//

import UIKit
import SDWebImage

extension UIImageView {

    /// 使用图像名称创建UIImageView
    ///
    /// - parameter imageName: 图片名imageName
    ///
    /// - returns: UIimageView
    convenience init(wl_imageName:String ) {
        self.init(image:UIImage(named:wl_imageName))
    }
    
    func wl_setImageWithURL(urlString:String?,placeholderName:String?){
        
        var placeholderImage :UIImage?
        
        if placeholderName != nil {
            placeholderImage = UIImage(named: placeholderName!)
        }
        
        guard let urlString = urlString,
            let url = NSURL(string:urlString) else {
            
            image = placeholderImage
            return
        }
    
        sd_setImage(with: url as URL, placeholderImage: placeholderImage)
    }
   
}

